<?php
namespace app\api\service;
use think\Service;
use app\admin\model\Order;
use app\admin\model\Admin;
use app\admin\model\admin\Balance;
class orderService
{
    static function fenMoney($ordernum = '')
    {   
        if($ordernum){
              $orderInfo= Order::where("ordernum",$ordernum)->where("is_pay",1)->find();
              if($find){
              		if($find['agent_id']){
              			 $rate = Admin::where("id",$find['agent_id'])->value("profit_rate");
						 $r = Balance::create([
	              			'admin_id'=>$find['agent_id'],
	              			'money'=>round(($rate/100)*$orderInfo['money'],2),
	              			'rate'=>$rate,
	    					'oid'=>$orderInfo['id']
              		     ]);

              		}
              		if($find['dealer_id']){
              			 $rate = Admin::where("id",$find['dealer_id'])->value("profit_rate"); 
              			 $r = Balance::create([
	              			'admin_id'=>$find['dealer_id'],
	              			'money'=>round(($rate/100)*$orderInfo['money'],2),
	              			'rate'=>$rate,
	    					'oid'=>$orderInfo['id']
              		     ]);
              		}


              }
             
        } 
        
    }
}